package com.foreknow.view;

import com.foreknow.bean.Guestbook;
import com.foreknow.service.impl.GuestbookServiceImpl;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;

public class Delete extends JFrame {

	private JPanel contentPane;
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Delete frame = new Delete();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Delete() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblid = new JLabel("\u8BF7\u8F93\u5165\u8981\u5220\u9664\u7684ID");
		lblid.setBounds(38, 10, 109, 28);
		contentPane.add(lblid);
		
		textField = new JTextField();
		textField.setBounds(157, 14, 66, 21);
		contentPane.add(textField);
		textField.setColumns(10);
		
		JLabel lblname = new JLabel("\u8981\u5220\u9664\u7684name\u4E3A");
		lblname.setBounds(38, 59, 116, 38);
		contentPane.add(lblname);
		
		textField_1 = new JTextField();
		textField_1.setBounds(157, 68, 66, 21);
		contentPane.add(textField_1);
		textField_1.setColumns(10);
		
		JLabel label = new JLabel("---------------------------------------------------------------------");
		label.setBounds(38, 48, 365, 8);
		contentPane.add(label);
		
		JLabel lblidwei = new JLabel("\u8981\u5220\u9664\u7684id\u4E3A");
		lblidwei.setBounds(38, 107, 102, 21);
		contentPane.add(lblidwei);
		
		textField_2 = new JTextField();
		textField_2.setBounds(157, 107, 66, 21);
		contentPane.add(textField_2);
		textField_2.setColumns(10);
		
		JButton button = new JButton("\u786E\u8BA4\u5220\u9664");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			GuestbookServiceImpl guestbookService = new GuestbookServiceImpl();
				int id = Integer.parseInt(textField.getText());
				Guestbook g = guestbookService.query(id);
				textField_1.setText(g.getName());
				textField_2.setText(g.getId().toString());
			int a = guestbookService.delete(id);
				System.out.println(a);
			}
		});
		button.setBounds(130, 174, 163, 44);
		contentPane.add(button);
		this.setVisible(true);
	}

}
